package com.zhixiang.xaec.service.safebase.securitySystem.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zhixiang.core.dao.BaseDao;
import com.zhixiang.core.service.impl.BaseServiceImpl;
import com.zhixiang.xaec.dao.safebase.securitySystem.InstituArchRevDao;
import com.zhixiang.xaec.entity.safebase.securitySystem.InstituArchRev;
import com.zhixiang.xaec.entity.safebase.securitySystem.InstitutionalArchives;
import com.zhixiang.xaec.service.safebase.securitySystem.InstituArchRevService;
import com.zhixiang.xaec.service.safebase.securitySystem.InstitutionalArchivesService;

@Service
public class InstituArchRevServiceImpl extends 
BaseServiceImpl<InstituArchRev,Long> implements InstituArchRevService{

    
    @Override
    @Resource(type=InstituArchRevDao.class)
    public void setBaseDao(BaseDao<InstituArchRev, Long> dao) {
       setDao(dao);
    }

    @Autowired
    private InstitutionalArchivesService institutionalArchivesService;
    
    @Override
    public String delete(String[] ids)
    {
       for(String id:ids){
           getDao().remove(Long.valueOf(id));
       }
        return null;
    }

    @Override
    public InstituArchRev getInstitutionalId(String id) {
        Object maxIdLong=null;
        List<InstituArchRev> lists=null;
        lists=getDao().findByHql("select max(id) from InstituArchRev where institutionalId=?", new Object[]{Long.valueOf(id)});
        for(int i=0;i<lists.size();i++){
            maxIdLong=lists.get(i);
        }
        if(maxIdLong==null){
            return null;
        }else{
            return getDao().get(Long.valueOf(maxIdLong.toString()));
        }
        
    }

    @Override
    public InstituArchRev saveIntituArchRev(InstituArchRev instituArchRev) {
        instituArchRev.setId(null);
        getDao().save(instituArchRev);
        InstitutionalArchives institutionalArchives=new InstitutionalArchives();
        institutionalArchives=institutionalArchivesService.get(instituArchRev.getInstitutionalId());
            institutionalArchives.setCreatDate(instituArchRev.getCreatDate());
            institutionalArchives.setCreaterName(instituArchRev.getCreaterName());
            institutionalArchives.setInstiDescribe(instituArchRev.getInstiDescribe());
            institutionalArchives.setInstilNo(instituArchRev.getInstilNo());
            institutionalArchives.setInstiName(instituArchRev.getInstiName());
            institutionalArchives.setInstitution(instituArchRev.getInstitution());
            institutionalArchives.setInstiVersion(instituArchRev.getInstiVersion());
            institutionalArchives.setRemark(instituArchRev.getRemark());
            institutionalArchives.setTaskEffiveTime(instituArchRev.getTaskEffiveTime());
            /*BeanUtils.copyProperties(institutionalArchives,instituArchRev);
            institutionalArchives.setId(id);*/
            institutionalArchivesService.save(institutionalArchives);
        return null;
    }

    @Override
    public List<InstituArchRev> findByIntitutionId(String id) {
        if(!"".equals(id)&&id!=null){
             return getDao().findByHql("FROM InstituArchRev p WHERE p.institutionalId=?", new Object[]{Long.valueOf(id)});
         }else{
             return null;
         }
    }
    
}
